home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best of www.BestZips.com (Collector's Edition)
/
Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO
/
tutorial
/
adatu311.zip
/
BOOK.ADA
< prev
next >
Wrap
Text File
|
1996-01-10
|
13KB
|
314 lines
-- BOOK.ADA Ver. 3.11 10-JAN-1996 Copyright 1988-1996 John J. Herro
--
-- SOFTWARE INNOVATIONS TECHNOLOGY http://members.aol.com/AdaTutor
-- 1083 MANDARIN DR NE ftp://members.aol.com/AdaTutor
-- PALM BAY FL 32905-4706
-- johnherro@aol.com
-- (407) 951-0233 john.herro%374-38-2@satlink.oau.org
--
-- This program creates two printable "book" files from the tutorial text in
-- ADA_TUTR.DAT. This is by no means required for the course, but is provided
-- because several users have asked for it. Be prepared to print about 500
-- pages! For the format of the input data file, please see the preliminary
-- comments in ADA_TUTR.ADA.
--
with Direct_IO, Text_IO; use Text_IO;
procedure Book is
subtype Block_Subtype is String(1 .. 64);
package Random_IO is new Direct_IO(Block_Subtype);
IxSize : constant := 35; -- Number of blocks in the index.
Data_File : Random_IO.File_Type; -- The file from which screens are read.
P : File_Type; -- The output file, to be printed.
Block : Block_Subtype; -- Block read from the input file.
Vpos : Integer; -- Number of the current block.
Hpos : Integer; -- Current position within current block.
Highest_SN : Integer; -- Highest screen number in the course.
Middle_SN : Integer; -- Screen number when we change output files.
Indx : String(1 .. 64*IxSize); -- Index from the Data File.
Answer : String(1 .. 80); -- User response to questions.
Len : Integer; -- Length of Answer.
File_OK : Boolean := False; -- True when data file opens successfully.
Legal_Note : constant String := " Copyright 1988-96 John J. Herro ";
-- Legal_Note isn't used by the program, but it causes
-- most compilers to place this string in the .EXE file.
procedure Open_Input_File is separate;
procedure Open_Output_File(S: in String) is separate;
procedure Print_Instructions is separate;
procedure Print_Title_Page is separate;
procedure Print_Screen(SN : in Integer) is separate;
begin
Open_Input_File;
if File_OK then
Print_Instructions;
Open_Output_File("FIRST");
Print_Title_Page;
Middle_SN := (101 + Highest_SN)/2;
for SN in 101 .. Highest_SN loop
if SN = Middle_SN then
Close(P);
Open_Output_File("SECOND");
end if;
Print_Screen(SN);
end loop;
Put_Line("Both book files are created and ready for printing.");
Random_IO.Close(Data_File);
Close(P);
end if;
end Book;
separate (Book)
procedure Open_Input_File is
Data_File_Name : constant String := "ADA_TUTR.DAT";
begin
Random_IO.Open(Data_File, Random_IO.In_File, Data_File_Name);
for I in 1 .. IxSize loop -- Read index from start of Data File.
Random_IO.Read(Data_File, Item => Block, From => Random_IO.Count(I));
Indx(64*I - 63 .. 64*I) := Block;
end loop;
Highest_SN := Integer'Value(Indx(6 .. 8));
File_OK := True;
exception
when Random_IO.Name_Error =>
Put("I'm sorry. The file " & Data_File_Name & " seems to be missing.");
when others =>
Put("I'm sorry. The file " & Data_File_Name);
Put_Line(" seems to have the wrong form.");
end Open_Input_File;
separate (Book)
procedure Open_Output_File(S: in String) is
OK : Boolean := False; -- True when file opens successfully.
begin
Put_Line("Please type the name of the output file for the " & S & " half");
Put("of the tutorial: ");
Get_Line(Answer, Len);
while not OK loop
begin
Create(File => P, Mode => Out_File, Name => Answer(1 .. Len));
OK := True;
exception
when others => null;
end;
if not OK then
Put_Line("Unable to create file. Please retype name: ");
Get_Line(Answer, Len);
end if;
end loop;
New_Line(2);
end Open_Output_File;
separate (Book)
procedure Print_Instructions is
begin
Put_Line("This program creates two printable ""book"" files from the");
Put_Line("tutorial text in ADA_TUTR.DAT. This is by no means required");
Put_Line("for the course, but is provided because several users have");
Put_Line("asked for it. Be prepared to print about 500 pages!");
New_Line(2);
end Print_Instructions;
separate (Book)
procedure Print_Title_Page is
S : constant String(1 .. 11) := (others => ' ');
begin
New_Page(P);
New_Line(P);
Put_Line(P,S & " AAA DDDD AAA TTTTT U U TTTTT RRRR");
Put_Line(P,S & " A A D D A A T U U T R R");
Put_Line(P,S & " AAAAA D D AAAAA === T U U T RRRR");
Put_Line(P,S & " A A D D A A T U U T R R");
Put_Line(P,S & " A A DDDD A A T UUU T R R");
New_Line(P);
Put_Line(P,S & "This is a copy of the tutorial text from ADA-TUTR, The");
Put_Line(P,S & "Interactive Ada Tutor, ver. 3.11. BEGIN WITH SCREEN 104.");
New_Line(P);
Put_Line(P,S & " Copyright 1988-1996 John J. Herro");
New_Line(P);
Put_Line(P,S & "You may copy this book, in printed or machine-readable");
Put_Line(P,S & "form, if you observe the Shareware notice in Screen 104.");
Put_Line(P,S & "Please distribute complete copies of the ADA-TUTR program");
Put_Line(P,S & "along with this book. If you don't have a copy of");
Put_Line(P,S & "ADA-TUTR, send $35 for a registered copy on a 3.5-inch");
Put_Line(P,S & "diskette for full use by one individual, or visit us on.");
Put_Line(P,S & "the World Wide Web, download a trial copy, and register");
Put_Line(P,S & "later for $25.");
New_Line(P);
Put_Line(P,S & " SOFTWARE INNOVATIONS TECHNOLOGY");
Put_Line(P,S & " 1083 MANDARIN DR NE");
Put_Line(P,S & " PALM BAY FL 32905-4706");
New_Line(P);
Put_Line(P,S & " (407) 951-0233");
New_Line(P);
Put_Line(P,S & " http://members.aol.com/AdaTutor");
Put_Line(P,S & " ftp://members.aol.com/AdaTutor");
New_Page(P);
New_Line(P);
end Print_Title_Page;
separate (Book)
procedure Print_Screen(SN : in Integer) is
Expanding : Boolean := False; -- True when expanding multiple spaces.
Literal : Boolean := False; -- True to print next character as is.
Prompting : Boolean := False; -- True for first character in a prompt.
Bold : Boolean := False; -- True when text is being emphasized.
Out1, Out2 : String(1 ..120) := (others => ' '); -- Lines of output text.
Place : Integer := 1; -- Current position within Out1 and Out2.
Limit : Integer; -- Position of last non-space char. in Out2.
Line_Num : Integer := 1; -- Current line being displayed.
Space : constant String(1 .. 69) := (others => ' ');
procedure Show(C : in Character) is separate;
procedure Screen_Char is separate;
procedure End_Of_Screen is separate;
begin
if SN = 103 then
Put(P, Space(1 .. 27) & "*** X TAKES YOU HERE. ***");
Put_Line(P, Space(1 .. 17) & "Screen 103");
else
Put_Line(P, Space & "Screen" & Integer'Image(SN));
end if;
New_Line(P, 2);
Vpos := 95*(Character'Pos(Indx(SN*4 - 394)) - 32) + -- Point to start
Character'Pos(Indx(SN*4 - 393)) - 32; -- of current
Hpos := Character'Pos(Indx(SN*4 - 392)) - 32; -- screen.
Random_IO.Read(Data_File, Item => Block, From => Random_IO.Count(Vpos));
while Block(Hpos) /= '[' or Expanding or Literal loop -- [ starts ctrl info.
Screen_Char;
end loop;
End_Of_Screen;
end Print_Screen;
separate (Book.Print_Screen)
procedure Show(C : in Character) is
begin
Out1(Place) := C;
if Bold then
Out2(Place) := '-';
end if;
Place := Place + 1;
end Show;
separate (Book.Print_Screen)
procedure Screen_Char is
procedure Process_Char is separate;
begin
if Expanding then
if Block(Hpos) = '!' then
Literal := True;
else
for I in Integer range 1 .. Character'Pos(Block(Hpos)) - 32 loop
Show(' ');
end loop;
end if;
Expanding := False;
elsif Literal then
Show(Block(Hpos));
Literal := False;
elsif Prompting then
Prompting := False;
if Block(Hpos) = 'b' then
Put(P, "Please type a space to go on, or B to go back.");
elsif Block(Hpos) = 'q' then
PUT(P, "Please type a space to go on, or B or Q to go ");
PUT(P, "back to the question.");
else
Process_Char;
end if;
else
Process_Char;
end if;
Hpos := Hpos + 1;
if Hpos > Block'Length then
Vpos := Vpos + 1;
Hpos := 1;
Random_IO.Read(Data_File, Block, From => Random_IO.Count(Vpos));
end if;
end Screen_Char;
separate (Book.Print_Screen.Screen_Char)
procedure Process_Char is
begin
case Block(Hpos) is
when '{' => Put_Line(P, Out1(1 .. Place - 1));
Limit := Out2'Last;
while Limit > 0 and then Out2(Limit) = ' ' loop
Limit := Limit - 1;
end loop;
Put_Line(P, Out2(1 .. Limit));
Out2 := (others => ' ');
Line_Num := Line_Num + 1;
Out1 := (others => ' ');
Place := 1;
when '@' => Expanding := True; -- @ = several spaces.
when '^' => Show(' '); -- ^ = bright + space.
Bold := True;
when '~' => Bold := False; -- ~ = normal + space.
Show(' ');
when '%' => Bold := True; -- % = bright.
when '`' => Bold := False; -- ` = normal.
when '}' => for I in Line_Num .. 23 loop -- } = go to line 24.
New_Line(P, 2);
end loop;
Prompting := True;
when '\' => Show(' '); -- \ = rev. vid. + sp.
when '$' => if SN = 103 then -- $ = screen #.
Show(' '); Show('_'); Show('_'); Show('_');
else
Show('$');
end if;
when '#' => if SN = 103 then -- # = % completed.
Show(' '); Show('_'); Show('_');
else
Show('#');
end if;
when others => Show(Block(Hpos));
end case;
end Process_Char;
separate (Book.Print_Screen)
procedure End_Of_Screen is
Ctrl_Info : Block_Subtype; -- Control info. for the current screen.
I : Integer; -- Used to index through Ctrl_Info.
begin
Put_Line(P, Out1(1 .. Place - 1));
Limit := Out2'Last;
while Limit > 0 and then Out2(Limit) = ' ' loop
Limit := Limit - 1;
end loop;
Put_Line(P, Out2(1 .. Limit));
Place := 1;
while Block(Hpos) /= ']' loop -- Read control information from Data File.
Hpos := Hpos + 1;
if Hpos > Block'Length then
Vpos := Vpos + 1;
Hpos := 1;
Random_IO.Read(Data_File, Block, From => Random_IO.Count(Vpos));
end if;
Ctrl_Info(Place) := Block(Hpos);
Place := Place + 1;
end loop;
if Ctrl_Info(1 .. Place - 1) = "]" then
Put_Line(P, "(Program ends after this screen.)");
elsif Ctrl_Info(1 .. Place - 1) = "#]" then
Put_Line(P, "(User types the next screen number.)");
else
I := 1;
while I + 4 < Place loop
Put(P, " '" & Ctrl_Info(I) & "' " & Ctrl_Info(I+1..I+3));
I := I + 4;
if I = 33 then
New_Line(P);
end if;
end loop;
New_Line(P);
end if;
New_Page(P);
New_Line(P);
end End_Of_Screen;